package com.xjtu.mybatisplus.web.controller;

import com.xjtu.mybatisplus.common.JsonResponse;
import com.xjtu.mybatisplus.model.domain.Article;
import com.xjtu.mybatisplus.model.dto.SearchDTO;
import com.xjtu.mybatisplus.model.esdocument.ESArticle;
import com.xjtu.mybatisplus.service.es.EsArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/api/search")
public class SearchController {
    @Autowired
    private EsArticleService esArticleService;

    @PostMapping("")
    @ResponseBody
    public JsonResponse search(@RequestBody SearchDTO searchDTO) {
        List<Article> articles = esArticleService.searchArticles(searchDTO.getSearchTerm());
        return JsonResponse.success(articles);
    }
}
